import { Injectable } from '@nestjs/common'
import { CreateCrudDto } from './dto/create-crud.dto'
import { UpdateCrudDto } from './dto/update-crud.dto'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository,Like } from 'typeorm'
import { Crud } from './entities/crud.entity'
@Injectable()
export class CrudService {
  constructor(
    @InjectRepository(Crud) private readonly crud: Repository<Crud>
  ) {}
  create(createCrudDto: CreateCrudDto) {
    const data = new Crud()
    data.name = createCrudDto.name
    data.desc = createCrudDto.desc
    return this.crud.save(data)
  }

  findAll(query: { keyword: string }) {
    return this.crud.find({
      where: {
        name:Like(`%${query.keyword}%`)
      }
    })
  }

  findOne(id: string) {
    return `This action returns a #${id} crud`
  }

  update(id: string, updateCrudDto: UpdateCrudDto) {
    return this.crud.update(id, updateCrudDto)
  }

  remove(id: string) {
    return this.crud.delete(id)
  }
}
